<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use common\components\widgets\Datetimepicker;
Datetimepicker::widget(['timepicker' => 'true','datepicker'=>'false','format'=>'H:i','step'=>'5']);
?>
<div class="yx-praise-list-box yx-praise-box yx-radius2 zx-min-height yx-add-content-box" >
    <?php $form = ActiveForm::begin(['enableAjaxValidation' => true,'enableClientValidation' => false,'options'=>['class'=>'form-validate']]); ?>
    <table width="100%" class="table-form" >
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['name']; ?></th>
            <td><?= $form->field($model, 'name', ['template' => '{input}{error}{hint}'])->textInput(['class' => 'input-text']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['room_number']; ?></th>
            <td><?= $form->field($model, 'room_number', ['template' => '{input}{error}{hint}'])->textInput(['class' => 'input-text']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['max_count']; ?></th>
            <td><?= $form->field($model, 'max_count', ['template' => '{input}{error}{hint}'])->textInput(['class' => 'input-text']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['type']; ?></th>
            <td><?= $form->field($model, 'type', ['template' => '{input}{error}{hint}'])->textInput(['class' => 'input-text']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['classroom_cate']; ?></th>
            <td style="display: inline-block;width: 206px"><?= $form->field($model, 'classroom_cate', ['template' => '{input}{error}{hint}'])->widget(\kartik\select2\Select2::className(),['data'=>$cate,'options' => ['placeholder' => '请选择分类','encode'=>false]]) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table" style="padding-bottom:10px;"><?= $model->attributeLabels()['classroom_cates']; ?></th>
            <td><?= $form->field($model, 'classroom_cates[]', ['template' => '{input}{error}{hint}'])->checkboxList($cate_checked,['class' => 'input-dropdownlist']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['area']; ?></th>
            <td><?= $form->field($model, 'area', ['template' => '{input}{error}{hint}'])->textInput(['class' => 'input-text']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['is_share']; ?></th>
            <td><?= $form->field($model, 'is_share', ['template' => '{input}{error}{hint}'])->radioList([0=>'否',1=>'是']) ?></td>
        </tr>
        <tr style="display: <?=$model->is_share == 1?'table-row':'none'?>" id="group">
            <th class="zx-goods-table"><?= $model->attributeLabels()['classroom_group_id']; ?></th>
            <td style="display: inline-block;width: 206px"><?= $form->field($model, 'classroom_group_id', ['template' => '{input}{error}{hint}'])->widget(\kartik\select2\Select2::className(),['data'=>$roomGroup,'options' => ['placeholder' => '请选择']]) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['info']; ?></th>
            <td style="padding-right:20px;"><?= $form->field($model, 'info', ['template' => '{input}{error}{hint}'])->widget(\doumiaoduo\ueditor\Ueditor::className(),['clientOptions'=>[
                    'serverUrl'=>\common\components\helpers\Fun::url(['/uploader/action']),
                    'toolbars'=>[['fullscreen', 'source', '|', 'undo', 'redo', '|','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript','rowspacingtop', 'rowspacingbottom', 'lineheight', '|','justifyleft', 'justifycenter', 'justifyright', 'justifyjustify','simpleupload','removeformat']],
                    'initialFrameWidth'=>'60%'
                ],]);?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['state']; ?></th>
            <td><?= $form->field($model, 'state', ['template' => '{input}{error}{hint}'])->radioList(['0'=>'未启用','1'=>'启用'],['prompt'=>'请选择分类','class' => 'input-dropdownlist']) ?></td>
        </tr>
    </table>
    <div class="yx-submit-box" style="width: 100%">
        <?= \yii\helpers\Html::submitButton('提交', ['class' => "button yx-submit", 'id' => 'dosubmit']) ?>
    </div>
</div>

<?php \yii\widgets\ActiveForm::end(); ?>

<script>
    //修改时，已选择分类复选框选中
    $(document).ready(function(){
        var v = $.trim($('input[id="classroom-name"]').val());
        if(!(v == "")){
            $('#classroom-classroom_cates input[type="checkbox"]').each(function() {
                $(this).attr('checked', true);
            });
        }
    });

    //教室授课分类
    $(function(){
        $('#classroom-classroom_cate').change(function(){
            var ids = new Array();
            $('#classroom-classroom_cates').each(function() {
                if ($(this).attr('checked') ==true) {
                    ids[$(this).val()] = $(this).val();
                }
            });

            id_cate = $('#classroom-classroom_cate').val();
            if($.inArray(id_cate, ids) == -1){
                str_cate = $('#classroom-classroom_cate').find("option:selected").text();
                str_cate = str_cate.replace("├", "");
                str_cate = str_cate.replace("└", "");

                html_cate = "<label><input type='checkbox' name='Classroom[classroom_cates][]' checked='checked' value='"+ id_cate +"'>"+str_cate+'</label>';
                $('#classroom-classroom_cates').append(html_cate);
            }
        });
    });

//    $('#classroom-classroom_cates input[type="checkbox"]').each(function(){
//        $('input[type="checkbox"]').click(function(){
//            if (!($(this).attr("checked"))) { //判断是否选中
//                 $(this).remove();
//            }
//        });
//    });

    $(document).on('change','input[name="Classroom[is_share]"]',function () {
        var val = $(this).val();
        if(val === '0'){
            $('#group').css('display','none')
        }else{
            $('#group').css('display','table-row')
        }
    })
</script>
